﻿@model ReportedOrder
@{
    Layout = null;
    ViewBag.Title = "下周订单";
}
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    @Html.Css("main", "flexigrid", "form", "list", "tree", "dp")
    <style>
        .ui-layout-top p
        {
            padding-left: 10px;
            padding-right: 30px;
            font-size: 14px;
            display: block;
            float: left;
            margin: 6px 0px 2px;
        }
        .ui-layout-top p span
        {
            font-size: 16px;
            font-weight: bold;
        }
    </style>
</head>
<body style="overflow: hidden; background: #dfe8f6">
    @Html.Js("jquery")
    <div class="ui-layout-top" style="background-color: #DFE8F6">
        <p>
            订单名称：<span>@Model.OrderName</span>
        </p>
        <p>
            日期：<span>@Model.BeginDate.ToString("yyyy-MM-dd")～@Model.EndDate.ToString("yyyy-MM-dd")</span>
        </p>
        <p>
            项目点：<span>@Model.SiteName</span>
        </p>
        <button id="btnReport" style="display: block; float: left; padding: 2px;">
            <span style="font-size: 16px;">上报订单</span></button>
        <p style="display: none">
            <a href="javascript:void(0);" id="btnImport"><span style="font-size: 14px; color: Blue;
                font-weight: normal; text-decoration: underline">导入订单</span></a>
        </p>
        <p>
            预计成本：<span style="color: Red">@Model.TotalCost</span></p>
        <p>
            订单状态：<span style="color: Blue">@Model.Status</span></p>
    </div>
    <div class="ui-layout-left">
        <div class="header">
            <span id="leftTitle" class="title">每日订单</span>
        </div>
        @(Html.nbTree(s =>
            {
                s.ID("Tree");
                s.Action(Url.Action("Tree", new { siteId = Model.SiteId, beginDate = Model.BeginDate, endDate = Model.EndDate }));
                s.layoutH(75);
                s.Width(200);
                s.Sync(false);
                s.Grid("orderId");
            }))
    </div>
    <div class="ui-layout-right">
        <div class="header">
            <span id="rightTitle" class="title">订单明细</span>
        </div>
        @(Html.nbGridFor<DishOrderItemView>(s =>
            {
                s.layoutW(208);
                s.layoutH(160);
                s.DefaultSortOption("MealType");
                s.Columns(c =>
                {
                    c.Bind(m => m.Id).IsKey();
                    c.Bind(m => m.MealType).Title("餐单分类").Width(50);
                    c.BindEnum(m => m.MainMaterialType, "MaterialCategory").Title("主料分类").Width(50);
                    c.BindEnum(m => m.Category, "DishType").Title("类别").Width(40);
                    c.Bind(m => m.Name).Title("菜肴名称").Width(100).AsQuery().Align(GridAlign.Left);
                    c.Bind(m => m.ItemDesc).Title("品名信息").Width("auto").Align(GridAlign.Left).AsQuery().AsQuery();
                    c.Bind(m => m.DishCost).Title("预计成本").Width(50).Align(GridAlign.Right);
                    c.Bind(m => m.Count).Title("客数").Width(40);
                    c.Bind(m => m.TotalCost).Title("预计总价").Width(60).Align(GridAlign.Right);
                    c.BindTemplate(130)
                        .Template(@<a href="@Url.OpenDialog(Url.Action("EditCount", new { itemId = "${Id}", orderId = "{TreeId}" }), "更改菜肴的订购客数", new { width = 350, height = 90 })" class="imgbtn2" ><span
                            class="accept">更改客数</span></a>)
                        .Template(Url.GridRowDeleteLink("Name", Url.Action("DeleteItem", new { itemId = "${Id}", orderId = "{TreeId}" })));
                });
                s.Buttons(b =>
                {
                    b.BindAddButton("添加菜肴").OnClick("AddDish");
                    b.Bind("批量更改客数", GridButtonType.Edit).OnClick("EditCounts");
                    b.Bind("添加备注", GridButtonType.Edit).OnClick("EditRemark");
                    b.BindDeleteButton(Url.Action("DeleteAllItem", new { orderId = "{TreeId}" }));
                });
            }))
    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        $("#btnReport").click(function () {
            OpenFormDialog('@Url.Action("ReportOrder", new { Id = Model.Id })', "上报订单");
        });
    });

    function EditRemark() {
        OpenModalDialog('@Url.Action("EditRemark")?orderId=' + $("#Tree").getTCT().id, {
            width: 610,
            height: 140,
            caption: "更改每日订单的备注"
        });
    }

    function EditCounts() {
        var ids = $("table.flexigrid").getCheckedRows(); //选中行的主键
        if (ids.length <= 0)
            alert("请您选择要更改客数的记录！");
        else {
            OpenModalDialog('@Url.Action("EditCount")?orderId=' + $("#Tree").getTCT().id + '&itemId=' + ids, {
                width: 350,
                height: 90,
                caption: "更改所选菜肴的订购客数",
                onclose: refreshGrid
            });
        }
    }

    function AddDish(type) {
        OpenModalDialog('@Url.Action("Lookup", "DishRange")?orderId=' + $("#Tree").getTCT().id + '&date=' + $("#Tree").getTCT().value,
        {
            width: 650,
            height: 600,
            caption: "从大菜单中添加菜肴",
            onclose: function (dishes) {
                if (dishes) {
                    // 转化数据，将Id更改为新的GUID
                    MapJsonArray(dishes, "Id", "Id");
                    MapJsonArray(dishes, "Cost", "DishCost");

                    var json = {};
                    json["Id"] = $("#Tree").getTCT().id;
                    json["items"] = dishes;

                    // 将数据保存到数据库中
                    ajaxTodo('@Url.Action("AddDish")', JSON.stringify(json), refreshGrid);
                }
            }
        });
    }
</script>
@Html.Js("common", "flexigrid", "tmpl", "list", "tree", "datepicker", "json2")
